#!/usr/bin/perl
# session_login.cgi
# Display the login form used in session login mode

$pragma_no_cache = 1;
require './web-lib.pl';
&init_config();
&ReadParse();
if ($gconfig{'loginbanner'} && $ENV{'HTTP_COOKIE'} !~ /banner=1/ &&
    !$in{'logout'} && !$in{'failed'} && !$in{'timed_out'}) {
	# Show pre-login HTML page
	print "Set-Cookie: banner=1; path=/\r\n";
	&PrintHeader();
	$url = $in{'page'};
	open(BANNER, $gconfig{'loginbanner'});
	while(<BANNER>) {
		s/LOGINURL/$url/g;
		print;
		}
	close(BANNER);
	return;
	}
print "Set-Cookie: banner=0; path=/\r\n" if ($gconfig{'loginbanner'});
print "Set-Cookie: user=x; path=/\r\n" if ($in{'logout'});
print "Set-Cookie: testing=1; path=/\r\n";
&header(undef, undef, undef, undef, 1, 1, undef, undef,
	"onLoad='document.forms[0].pass.value = \"\"; document.forms[0].user.focus()'");

print "<style type=\"text/css\">\n",
	"BODY {
	font-family:verdana, tahoma, sans-serif;
	}",
      "table.title {
	font-family:Arial, Helvetica, sans-serif;
	font-size:9pt;
	background-color: #90c8ff;
	border-color: #000000;
	border-left-style: solid;
	border-right-style: solid;
	border-top-style: solid;
	border-bottom-style: solid;
	border-width: 1;
	}",
	"table.mode1 {
	font-family:verdana, tahoma, sans-serif;
	font-size:9pt;
	border-color: #000000;
	}",
	"tr.mode2 {
	background-color: #e8f4ff;
	}",
	"input.button1 {
	font-family:verdana, tahoma, sans-serif;
	font-size:9pt;
	border-style: solid;
	border-width: 1;
	background-color: #c8e4ff;
	cursor: hand;
	width: 80;
	border-color: #000000;
	}",
	"input.text {
	font-family:verdana, tahoma, sans-serif;
	font-size:9pt;
	border-style: solid;
	border-width: 1;
	background-color: #ffffff;
	border-color: #000000;
	}",
      "</style>\n";

#print "<hr>\n";
print "<br>";
print "<center>\n";
if (defined($in{'failed'})) {
	print "<h3>$text{'session_failed'}</h3><p>\n";
	}
elsif ($in{'logout'}) {
	print "<h3>$text{'session_logout'}</h3><p>\n";
	}
elsif ($in{'timed_out'}) {
	print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
	}
print "<form action=/session_login.cgi method=post>\n";
print "<input type=hidden name=page value='".&html_escape($in{'page'})."'>\n";
print "<table class=title border=0 cellspacing=0 width=350>\n";
my $var_sessionheader = &text('session_header', $gconfig{'mainbrand'});
print "<tr class=title1> <td><b>$var_sessionheader</b></td> </tr>\n";
print "<tr class=mode2> <td align=center><table class=mode1 cellpadding=3>\n";
$host = $ENV{'HTTP_HOST'};
$host =~ s/:\d+//g;
print "<tr> <td colspan=2 align=left>",
      &text($gconfig{'nohostname'} ? 'session_mesg2' :
	    $gconfig{'usermin'} ? 'session_mesg3' : 'session_mesg',
	    "<tt>$host</tt>", $gconfig{'mainbrand'}),"</td> </tr>\n";
print "<tr> <td nowrap><b>$text{'session_user'}</b></td>\n";
print "<td><input name=user size=35 value='".&html_escape($in{'failed'})."' class=text></td> </tr>\n";
print "<tr> <td nowrap><b>$text{'session_pass'}</b></td>\n";
print "<td><input name=pass size=35 type=password class=text></td> </tr>\n";
print "<tr> <td></td><td colspan=2><input type=submit value='$text{'session_login'}' class=button1>\n";
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value='$text{'session_clear'}' class=button1></td><br>\n";
if (!$gconfig{'noremember'}) {
	print "<input type=checkbox name=save value=1> $text{'session_save'}\n";
	}
print "</td> </tr>\n";
print "</table></td></tr></table><p>\n";
print "</form></center>\n";
&footer();

